package leetcode;

/**
 * 704
 */
class Solution2 {
    public int search(int[] nums, int target) {
        return search(nums,0,nums.length-1,target);

    }

    private int search(int[] nums, int left, int right, int target) {

        while (left <= right){
            int mid = left+ (right-left)/2;
            if(nums[mid]==target){
                return mid;
            }else if(nums[mid] < target){
                left = mid+1;
            }else {
                right = mid-1;
            }
        }
        return  -1;
    }
}